import request from '@/utils/request'

/**
 * 获取通讯录列表
 * @returns {Promise<AxiosResponse<any>>}
 */
export const getAddressList = () => {
  return request.get('contact/list')
}

/**
 * 好友请求数量
 * @returns {Promise<AxiosResponse<any>>}
 */
export const requestCount = () => {
  return request.get('contact/user/request/count')
}

/**
 * 获取好友请求列表
 * @returns {Promise<AxiosResponse<any>>}
 */
export const getRequestList = () => {
  return request.get('contact/user/request/list')
}

/**
 * 搜索用户
 * @param phone 手机号码
 * @returns {Promise<AxiosResponse<any>>}
 */
export const searchUser = (phone) => {
  return request.get(`contact/user/search/${phone}`)
}

/**
 * 发送好友请求
 * @param {id} invitationTo 被邀请人的ID
 * @param {string} invitationMsg 邀请信息
 * @returns {Promise<AxiosResponse<any>>}
 */
export const sendRequest = (invitationTo, invitationMsg) => {
  return request.put('contact/user/request/send', {
    invitation_to: invitationTo, invitation_msg: invitationMsg
  })
}

/**
 * 查看好友请求详情
 * @param {number} invitationID 请求ID
 * @returns {Promise<AxiosResponse<any>>}
 */
export const requestDetail = (invitationID) => {
  return request.get(`contact/user/request/detail/${invitationID}`)
}

/**
 * 处理好友请求
 * @param {number} invitationID 邀请ID
 * @param {number} invitationState 邀请状态
 * @returns {Promise<AxiosResponse<any>>}
 */
export const requestHandle = (invitationID, invitationState) => {
  return request.post('contact/user/request/handle', {
    invitation_id: invitationID,
    state: invitationState
  })
}

/**
 * 删除好友
 * @param {number} deleteID 被删除的用户ID
 * @returns {Promise<AxiosResponse<any>>}
 */
export const deleteFriend = (deleteID) => {
  return request.delete('contact/user/delete/' + deleteID)
}

/**
 * 用戶信息详情
 * @param {number} userID 用戶ID
 * @returns {Promise<AxiosResponse<any>>}
 */
export const userDetail = (userID) => {
  return request.get(`contact/user/detail/${userID}`)
}

/**
 * 删除最近联系人
 * @param {number} userID 要删除最近联系人的用户ID
 * @returns {Promise<AxiosResponse<any>>}
 */
export const deleteRecent = (userID) => {
  return request.delete(`contact/recent/delete/${userID}`)
}

/**
 * 删除最近联系人
 * @param {number} userID 要删除最近联系人的用户ID
 * @returns {Promise<AxiosResponse<any>>}
 */
export const changeRemarks = (userID, remarks) => {
  return request.put('/contact/user/remarks/set', {
    user_id: userID,
    remarks
  })
}

/**
 * 删除消息记录
 * @param { number } targetID 目标人员id
 * @param { array } messageIDS 带删除的消息列表
 * @returns {*}
 */
export const contactMessageDelete = (targetID, messageIDS) => {
  return request.put('contact/message/delete', {
    target_id: targetID,
    messageIDS
  })
}

/**
 * 删除所有消息记录
 * @param {number} userID 要删除记录联系人的用户ID
 * @returns {*}
 */
export const contactMessageDeleteAll = (userID) => {
  return request.delete(`contact/message/deleteAll/${userID}`)
}
